import React, { Component } from 'react';
import {
  Alert, StyleSheet, Text, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback, View,
} from 'react-native';

/**
 * TouchableHighlight 背景会在按下时变暗。
 * TouchableOpacity 按下时降低按钮的透明度，而不会改变背景的颜色。
 * 不显示任何视觉反馈，用TouchableWithoutFeedback。
 * 长按操作，用onLongPress属性来实现
 */
class MyComponent extends Component {
  onPressButton() {
    Alert.alert('You tapped the button!');
  }

  onLongPressButton() {
    Alert.alert('You long-pressed the button!');
  }


  render() {
    return (
      <View style={styles.container}>
        <TouchableHighlight onPress={this.onPressButton} underlayColor="white">
          <View style={styles.button}>
            <Text style={styles.buttonText}>TouchableHighlight</Text>
          </View>
        </TouchableHighlight>
        <TouchableOpacity onPress={this.onPressButton}>
          <View style={styles.button}>
            <Text style={styles.buttonText}>TouchableOpacity</Text>
          </View>
        </TouchableOpacity>
        <TouchableWithoutFeedback
          onPress={this.onPressButton}
        >
          <View style={styles.button}>
            <Text style={styles.buttonText}>TouchableWithoutFeedback</Text>
          </View>
        </TouchableWithoutFeedback>
        <TouchableHighlight onPress={this.onPressButton} onLongPress={this.onLongPressButton} underlayColor="white">
          <View style={styles.button}>
            <Text style={styles.buttonText}>Touchable with Long Press</Text>
          </View>
        </TouchableHighlight>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    paddingTop: 60,
    alignItems: 'center',
  },
  button: {
    marginBottom: 30,
    width: 260,
    alignItems: 'center',
    backgroundColor: '#2196F3',
  },
  buttonText: {
    padding: 20,
    color: 'white',
  },
});
export default MyComponent;
